package com.audaque.springboot.foshanupload.web.springsecuritycas.config;

import org.jasig.cas.client.session.SingleSignOutFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.cas.web.CasAuthenticationFilter;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.logout.LogoutFilter;

/**
 * @author zgb
 * @desc security专属配置
 * @date 2022-12-12 23:44:19
 */
/*
@EnableWebSecurity(debug = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private AuthenticationProvider authenticationProvider;

    @Autowired
    private AuthenticationEntryPoint entryPoint;

    @Autowired
    private CasAuthenticationFilter casAuthenticationFilter;

    @Autowired
    private SingleSignOutFilter singleSignOutFilter;

    @Autowired
    private LogoutFilter requestSingleLogoutFilter;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) {

        auth.authenticationProvider(authenticationProvider);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/security/user")
                .hasRole("USER")
                //验票地址：http://localhost:8081/service/login?ticket=ST-1580-LgEmkRspmjFXz3PT7JxNfvnwhwk-LAPTOP-BSQ5FM3V
                .antMatchers("/service/login?ticket=*","/security/dept", "/favicon.ico", "/error")
                .permitAll()
                .anyRequest()
                .authenticated()
                .and()
                .exceptionHandling()
                //配置CAS鉴证失败处理器： 将客户端登录地址绑定到服务端登录地址，实现客户端登录地址重定向到服务端登录地址
                .authenticationEntryPoint(entryPoint)
                .and()
                //s:添加cas过滤器
                //设置cas认证处理逻辑：将客户端登录地址绑定到服务端登录地址，实现服务端登录后回调到客户端登录方法内
                .addFilter(casAuthenticationFilter)
                //处理认证逻辑
                .addFilterBefore(singleSignOutFilter, CasAuthenticationFilter.class)
                //配置CAS登出入口:将客户端登出地址绑定到服务端登出地址，实现客户端登出地址重定向到服务端登出地址
                .addFilterBefore(requestSingleLogoutFilter, LogoutFilter.class)
                //e:添加cas过滤器
        ;
    }

}
*/
